/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package RoomTransaction;

import Address.AddressBean;
import Admission.AdmissionBean;
import Category.CategoryBean;
import Course.CourseBean;
import Student.StudentBean;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author mishra
 */
public class CheckAccountDetails extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        Vector<Object> list=new Vector<Object>();
        Vector<Object> list1=new Vector<Object>();
        try {
            int admisId=0, feeTye=0;
            
            admisId=Integer.parseInt(request.getParameter("admiId"));
            feeTye=Integer.parseInt(request.getParameter("feeTypeId"));
            
            StudentBean st=Student.Query.viewSpecific(admisId);
            
            if(st.getStudentId()!=0){
            
            AdmissionBean adm=st.getAdmissionBean();
            AddressBean addb=st.getAddressBean();
            CourseBean cob= adm.getCourseBean();
            CategoryBean cab=st.getCategoryBean();
             String unique = "--"+feeTye+"--"+admisId+"--"+adm.getSemester()+"--"+cab.getCategoryId();
             
            list=RoomTransaction.Query.checkPaid(unique);
            list1=RoomTransaction.Query.viewAllotedRoomDetail(admisId);
            if(!list.isEmpty()){
            out.println("<legend>Student Hostel Account Details</legend>");
            
            out.println("<div id='lside' style='float: left; margin-top: 10px;'>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Total Room Charge:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='totalval' name='totalval' value='"+list.get(0) +"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("</div>");
            
            out.println("<div id='rside' style='float: left; margin-right: 120px; margin-top: 10px'>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Paid Amount:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='paidval' name='paidval' value='"+list.get(1) +"'>");
            out.println("</div>");
            out.println("</div>");
            
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Balance Amount:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='due' name='due' value='"+list.get(2) +"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("</div>");
           
            if(!list1.isEmpty() && Integer.parseInt(list1.get(5).toString())==1){
            out.println("<legend>Hostel, Room, Bed Details</legend>");
            out.println("<div id='lside' style='float: left; margin-top: 10px;'>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Hostel Name:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='hname' name='hname' value='"+list1.get(0)+"'>");
            out.println("<input type='hidden' id='hostelid' name='hostelid' value='"+list1.get(3)+"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("</div>");
            
            out.println("<div id='rside' style='float: left; margin-right: 120px; margin-top: 10px'>");
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Room Number:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='roomno' name='roomno' value='"+list1.get(2) +"'>");
            out.println("</div>");
            out.println("</div>");
           
            
            out.println("<div class='control-group'>");            
            out.println("<label for='feeTypeid' class='control-label'>Bed Number:</label>");            
            out.println("<div class='controls'>");
            out.println("<input type='text' readOnly id='bedno' name='bedno' value='"+list1.get(1) +"'>");
            out.println("<input type='hidden' id='bedid' name='bedid' value='"+list1.get(4) +"'>");
            out.println("</div>");
            out.println("</div>");
            
            out.println("</div>");
            }
            else{
                out.println("<legend>Allotement Details</legend>");
                out.println("<div style='margin-top: 10px;' class='control-label'>");
                out.println("<center><h4 style='color: red'>Room Not Alloted!!</h4></center>");
                out.println("</div>");
            }
            
            }
            else{
                out.println("<div style='margin-top: 80px;'>");
                out.println("<legend>Room Alloted or NOt</legend>");
                out.println("<center><h4 style='color: red'>Room Not Alloted and Not Paid Fees For Room Allotment!!</h4></center>");
                out.println("</div>");
            }
            }
            else{
                out.println("<div style='margin-top: 80px;'>");
                out.println("<legend>Room Alloted or NOt</legend>");
                out.println("<center><h4 style='color: red'>Student Record Not Found!!</h4></center>");
                out.println("</div>");
            }
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(CheckAccountDetails.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(CheckAccountDetails.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
